local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.CharacterObject());
local InstanceManager = CommonOHOH.load.InstanceManager();

local StateMachine=CommonOHOH.load.StateMachine()


function M.new(...)
	return M(...);
end;

function M.ctor(self,character)
	
    M.super.ctor(self,character);

     self.player=_G.client.local_player
     self.StateMachine=StateMachine.new()

     self.StateMachine:CreateState("idle") --idle 状态
     self.StateMachine:CreateState("upgrade")--升级状态
     self.StateMachine:CreateState("equip")--切换为装备状态
     self.StateMachine:CreateState("changeWeapon")--改变武器

     self.ShowStateMachine=StateMachine.new() --  显示状态

     self.ShowStateMachine:CreateState("show") --显示
     self.ShowStateMachine:CreateState("hide")--隐藏


    self:AddPrivateComponentByFolder(script.com)
    
    self.StateMachine:SwitchState("idle")
    -- self.ShowStateMachine:SwitchState("hide")

    self.WeaponCtrl= self:GetPrivateComponent("weapon")
end


--析构函数
function M.dtor(self)

    self.StateMachine:dtor()
    local obj= self.main_inst
    M.super.dtor(self);
    obj:Destroy()

end;


function M.SetWeapon(self,weaponId)
    self.WeaponCtrl:SetWeapon(weaponId)
end


-- 获取状态
function M.GetState(self,id)
    return self.StateMachine:GetState(id)
end


-- 切换状态
function M.SwitchState(self,id)
    self.StateMachine:SwitchState(id)
end

--获取当前状态
function M.GetCurrentState(self)
    self.StateMachine:GetCurrentState()
end

function M.GetShowState(self,id)
    return self.ShowStateMachine:GetState(id)
end

--显示
function M.Show(self,cf)
    self:SetCFrame(cf)
    self.ShowStateMachine:SwitchState("show")
end

--隐藏
function M.Hide(self,cf)
    self:SetCFrame(cf)
    self.ShowStateMachine:SwitchState("hide")
end

--升级
function M.Upgrade(self)
    self.StateMachine:SwitchState("upgrade")
    self:AddProcess(function()
        self:Wait(2) --3秒后，切换为idle状态
        self.StateMachine:SwitchState("idle")
    end)
end

--切换武器
function M.ChangeWeapon(self,wid)
    self:SetWeapon(wid)
    self.StateMachine:SwitchState("changeWeapon")
    self:AddProcess(function()
        self:Wait(1) --3秒后，切换为idle状态
        self.StateMachine:SwitchState("idle")
    end)
end



-- 切换为装备
function M.Equip(self)
    self.StateMachine:SwitchState("equip")
    self:AddProcess(function()
        self:Wait(1) --3秒后，切换为idle状态
        self.StateMachine:SwitchState("idle")
    end)
end

return M
